package t4;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import t4bean.PurchaseDateBean;
import t4bean.PurchaseOrderBean;
import t4bean.SalesvolumDateBean;
import t4bean.SalesvolumeRecordBean;
import t4bean.StallBean;
import t4bean.StockBean;

public class Deserialization {
	public StallBean deserialization() throws IOException {
		List<StockBean> stockList = new ArrayList<StockBean>();
		List<PurchaseOrderBean> purList = new ArrayList<PurchaseOrderBean>();
		List<SalesvolumeRecordBean> salList = new ArrayList<SalesvolumeRecordBean>();
		List<PurchaseDateBean> purDateList = new ArrayList<PurchaseDateBean>();
		List<SalesvolumDateBean> salDateList = new ArrayList<SalesvolumDateBean>();

		FileReader fr = new FileReader("D:\\T1\\stall.txt");
		BufferedReader br = new BufferedReader(fr);

		while (true) {
			String stockNumber = br.readLine();
			if (stockNumber.equals("")) {
				break;
			}
			String fruitCost = br.readLine();
			String fruitPrice = br.readLine();
			String fruitName = br.readLine();
			FruitBean fruit = new FruitBean(fruitName, Integer.parseInt(fruitPrice), Integer.parseInt(fruitCost));
			StockBean sto = new StockBean(fruit, Integer.parseInt(stockNumber));
			stockList.add(sto);
		}
		while (true) {
			String fruitCost = br.readLine();
			if (fruitCost.equals("")) {
				break;
			}
			String fruitPrice = br.readLine();
			String fruitName = br.readLine();
			FruitBean fruit = new FruitBean(fruitName, Integer.parseInt(fruitPrice), Integer.parseInt(fruitCost));
			String purchaseQuantity = br.readLine();
			PurchaseOrderBean pur = new PurchaseOrderBean(fruit, Integer.parseInt(purchaseQuantity));
			purList.add(pur);
		}
		while (true) {
			String discount = br.readLine();
			if (discount.equals("")) {
				break;
			}
			String fruitCost = br.readLine();
			String fruitPrice = br.readLine();
			String fruitName = br.readLine();
			FruitBean fruit = new FruitBean(fruitName, Integer.parseInt(fruitPrice), Integer.parseInt(fruitCost));
			String salesVolume = br.readLine();
			SalesvolumeRecordBean sal = new SalesvolumeRecordBean(fruit, Integer.parseInt(salesVolume),
					Integer.parseInt(discount));
			salList.add(sal);
		}
		while (true) {
			String day = br.readLine();
			if (day.equals("")) {
				break;
			}
			String month = br.readLine();
			String fruitCost = br.readLine();
			String fruitPrice = br.readLine();
			String fruitName = br.readLine();
			FruitBean fruit = new FruitBean(fruitName, Integer.parseInt(fruitPrice), Integer.parseInt(fruitCost));
			String purchaseQuantity = br.readLine();
			PurchaseOrderBean po = new PurchaseOrderBean(fruit, Integer.parseInt(purchaseQuantity));
			PurchaseDateBean purDate = new PurchaseDateBean(fruit, po, Integer.parseInt(month), Integer.parseInt(day));
			purDateList.add(purDate);
		}
		while (true) {
			String day = br.readLine();
			if (day.equals("")) {
				break;
			}
			String month = br.readLine();
			String fruitCost = br.readLine();
			String fruitPrice = br.readLine();
			String fruitName = br.readLine();
			FruitBean fruit = new FruitBean(fruitName, Integer.parseInt(fruitPrice), Integer.parseInt(fruitCost));
			String srDiscount = br.readLine();
			String srSalesVolume = br.readLine();
			SalesvolumeRecordBean sr = new SalesvolumeRecordBean(fruit, Integer.parseInt(srSalesVolume),
					Integer.parseInt(srDiscount));
			SalesvolumDateBean salDate = new SalesvolumDateBean(fruit, sr, Integer.parseInt(month),
					Integer.parseInt(day));
			salDateList.add(salDate);
		}

		StallBean stall = new StallBean(purList, salList, stockList, purDateList, salDateList);
		br.close();
		return stall;
	}
}
